package com.jastar.android.jigsaw.item;

import com.jastar.android.jigsaw.R;
import com.jastar.android.jigsaw.util.RandomUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class JigsawImage {

    private static final List<JigsawImage>[] list;
    private static final int LEVEL_COUNT = 3;

    static {
        list = new List[LEVEL_COUNT];
        IntStream.range(0, LEVEL_COUNT).forEach(i -> list[i] = new ArrayList<>());
        list[0].add(new JigsawImage(R.drawable.image01, 4, 2));
        list[0].add(new JigsawImage(R.drawable.image05, 4, 2));
        list[0].add(new JigsawImage(R.drawable.image09, 4, 2));
        list[0].add(new JigsawImage(R.drawable.image02, 4, 3));
        list[0].add(new JigsawImage(R.drawable.image04, 3, 4));

        list[1].add(new JigsawImage(R.drawable.image03, 5, 4));
        list[1].add(new JigsawImage(R.drawable.image08, 5, 4));
        list[1].add(new JigsawImage(R.drawable.image10, 5, 4));
        list[1].add(new JigsawImage(R.drawable.image12, 5, 4));
        list[1].add(new JigsawImage(R.drawable.image15, 5, 4));

        list[2].add(new JigsawImage(R.drawable.image11, 7, 4));
        list[2].add(new JigsawImage(R.drawable.image13, 6, 5));
        list[2].add(new JigsawImage(R.drawable.image16, 6, 5));
        list[2].add(new JigsawImage(R.drawable.image17, 6, 5));
        list[2].add(new JigsawImage(R.drawable.image18, 6, 5));
    }

    int imageId;
    int xNum;
    int yNum;

    public static JigsawImage getImage(int level) {
        if (level < 0 || level >= LEVEL_COUNT) throw new IllegalArgumentException("Illegal level.");
        return RandomUtil.randomListItem(list[level]);
    }

    public JigsawImage(int imageId, int xNum, int yNum) {
        this.imageId = imageId;
        this.xNum = xNum;
        this.yNum = yNum;
    }

    public int getImageId() {
        return imageId;
    }

    public int getxNum() {
        return xNum;
    }

    public int getyNum() {
        return yNum;
    }

}
